/******************************************************************************
 * $Id: globals.h,v 1.19 2004/12/25 16:30:56 jimb Exp $
 * @file
 * @author  Jim Brooks http://www.jimbrooks.org
 * @brief   Global vars.
 * @remarks There's a lot of globals but they don't cause any bad side-effects.
 ******************************************************************************/

#ifndef GLOBALS_H
#define GLOBALS_H

#ifdef HYPERSRC_DEFINE_GLOBALS
#define GLOBAL
#define INIT(x) = x
#else
#define GLOBAL		extern
#define INIT(x) 
#endif

#define gtk_signal g_signal

/*
 * Pointers to widgets.
 */
GLOBAL GtkWidget*      pWidgetMain;
GLOBAL GtkWidget*      pWidgetVboxMain;
GLOBAL GtkWidget*      pWidgetToolbar;

GLOBAL GtkWidget*      pWidgetToolbar2;	        // (lv)
GLOBAL GtkWidget*      pWidgetOptionMenuForToolbar ;
GLOBAL GtkWidget*      pWidgetComboFuncList;

GLOBAL GtkWidget*      pWidgetToolbarButtonGotoLine;
GLOBAL GtkWidget*      pWidgetToolbarButtonGotoTag;
GLOBAL GtkWidget*      pWidgetToolbarButtonLaterTag;
GLOBAL GtkWidget*      pWidgetToolbarButtonEarlierTag;
GLOBAL GtkWidget*      pWidgetToolbarButtonFindMatches;
GLOBAL GtkWidget*      pWidgetToolbarButtonRecordCursor;
GLOBAL GtkWidget*      pWidgetNotebook;
GLOBAL GtkWidget*	   pWidgetNotebookFiles;	// for opened files (lv)
GLOBAL GtkWidget*      pWidgetNotebookFind;     // for find/func_tree(lv)
GLOBAL GtkWidget*      pWidgetModuleTree;
GLOBAL GtkWidget*      pWidgetFuncTreeRoot;
GLOBAL GtkWidget*      pWidgetFrameFuncTree;
GLOBAL GtkWidget*      pWidgetClistTags;
GLOBAL GtkWidget*      pWidgetClistFound;
GLOBAL GtkWidget*      pWidgetClistModules;
GLOBAL GtkWidget*      pWidgetClistHistory;
GLOBAL GtkWidget*      pWidgetScrolledTags;
GLOBAL GtkWidget*      pWidgetScrolledFound;
GLOBAL GtkWidget*      pWidgetScrolledModules;
GLOBAL GtkWidget*      pWidgetScrolledHistory;
GLOBAL GtkWidget*      pWidgetScrolledModuleTree;
GLOBAL GtkWidget*      pWidgetScrolledFuncTree;
GLOBAL GtkWidget*      pWidgetTextMain;
GLOBAL GtkWidget*      pWidgetTextAux;
GLOBAL GtkWidget*      pWidgetTextActive;		/* points to either main/aux 
                                                   text widgets */
GLOBAL GtkWidget*      pWidgetVboxTextMain;
GLOBAL GtkWidget*      pWidgetTableTextMain;
GLOBAL GtkWidget*      pWidgetHscrollTextMain;
GLOBAL GtkWidget*      pWidgetVscrollTextMain;

GLOBAL GtkWidget*      pWidgetVboxTextAux;
GLOBAL GtkWidget*      pWidgetTableTextAux;
GLOBAL GtkWidget*      pWidgetHscrollTextAux;
GLOBAL GtkWidget*      pWidgetVscrollTextAux;

GLOBAL GtkWidget*      pWidgetPaned;
GLOBAL GtkWidget*      pWidgetPanedFuncTree;
GLOBAL GtkWidget*      pWidgetPanedText;
GLOBAL GtkWidget*      pWidgetStatusbar;
GLOBAL GtkWidget*      pWidgetDialogFind;
GLOBAL GtkWidget*      pWidgetDialogLine;
GLOBAL GtkWidget*      pWidgetComboFind;
GLOBAL GtkWidget*      pWidgetComboLine;
GLOBAL GtkWidget*      pWidgetCheckButtonFindExact;
GLOBAL GtkWidget*      pWidgetCheckButtonFindCase;
GLOBAL GtkWidget*      pWidgetCheckButtonFindGlobal;
GLOBAL GtkWidget*      pWidgetCheckButtonFindReverse;
GLOBAL GtkWidget*      pWidgetCheckButtonFindRegex;
GLOBAL GtkWidget*      pWidgetCheckButtonFunctree;
GLOBAL GtkWidget*      pWidgetFontSel;
GLOBAL GtkWidget*      pWidgetWithFocus;
GLOBAL GtkAccelGroup*  pAccelGroup;
GLOBAL GtkItemFactory* pItemFactory;

/*
 * Text widget state.
 */
GLOBAL cursor_t		cursorText;
GLOBAL int			textWidgetBehavior INIT(DONT_SWITCH_UNLESS_AUX_TEXT_KEY);
GLOBAL int			scrolling  INIT(0); /* reported if SIGSEGV happens */
GLOBAL int			scrollLine INIT(0); /* reported if SIGSEGV happens */

/*
 * Focusbars.
 */
GLOBAL focusbar_t*	pFocusbarTextMain;
GLOBAL focusbar_t*	pFocusbarTextAux;
GLOBAL focusbar_t*	pFocusbarTextActive;
GLOBAL gboolean		keepFocusbarLit INIT(TRUE); /* if TRUE, focusbars over text widgets tend to stay lit, even when other widgets have the focus */

/*
 * Tag and tag clist widget state.
 */
GLOBAL GList*		pGlistModuleOpened;				/* Pointer to the opened module(file) currently, module_opened_t struct(lv) */
GLOBAL GList*		pGlistTags;						/* pointer to a glist of tag_t structs */
GLOBAL GHashTable*	pHashTagsFabricated;			/* tags fabricated by hypersrc */
GLOBAL GHashTable*	pHashFuncTagsAll;				/* all func/macro/method tags */
GLOBAL int			ctagsLines;						/* inc'd by ProcessCtagsBuf() */
GLOBAL int			tagsCnt;						/* same as g_list_length( pGlistTags ) */
GLOBAL GList*		pGlistFoundTags;				/* list of tagged lines resulting from Find/Global */
GLOBAL int			widgetTagsClistWidthCol[WIDGET_TAGS_CLIST_COLUMNS];
GLOBAL int			widgetFoundClistWidthCol[WIDGET_FOUND_CLIST_COLUMNS];
GLOBAL gint			widgetTagsClistSelectedRow INIT(ROW_NONE);
GLOBAL int			tagSortInitial INIT(SORT_UNSORTED);		/* how tags are initially sorted */
GLOBAL int			tagsSorted;								/* amount of sorted tags */
GLOBAL int			tagsSortedPercentShown;					/* {0,5,10,..95} percentage being shown by statusbar */
GLOBAL int			textLeft INIT(FALSE);
GLOBAL int			textLeftApplied;
GLOBAL int			tagsColumnsLayout INIT(TAG_COL_LAYOUT_TAG_MODULE_TYPE_LINE);
GLOBAL int			tagsLineColumn INIT(3);

/*
 * Modules clist widget state.
 */
GLOBAL int			widgetModulesClistWidthCol[WIDGET_MODULES_CLIST_COLUMNS];
GLOBAL gint			widgetModulesClistSelectedRow INIT(ROW_NONE);
GLOBAL int			returnEarlyModuleSelectCallback INIT(FALSE);

/*
 * History clist widget state.
 */
GLOBAL int			widgetHistoryClistWidthCol[WIDGET_HISTORY_CLIST_COLUMNS];
GLOBAL gint			widgetHistoryClistSelectedRow INIT(ROW_NONE);
GLOBAL gboolean		prependingTagHistory INIT(FALSE);
GLOBAL gboolean		activeHistoryRowSelect INIT(FALSE);
GLOBAL GSList*		pGslistHistoryCursor;					/* records cursor positions */

/*
 * State for all clists.
 */
GLOBAL gboolean		rowSelectedByProgram INIT(0);

/*
 * Tree state.
 */
GLOBAL gboolean		funcTreeVerbose INIT(TRUE);				/* also affects module tree */
GLOBAL gboolean		disableFuncTreeUpdates INIT(FALSE);		/* corresponds to a check button */
GLOBAL gboolean		fontifyFuncTrees INIT(TRUE);			/* whether to use different fonts in func trees */

/*
 * Notebook state.
 */
GLOBAL gint			notebookPageWithSelectedRow;
GLOBAL gboolean		notebookPageFound INIT(FALSE);
GLOBAL gboolean		kludgeNotebookSwitchPage INIT(FALSE);
GLOBAL gboolean		autoSelectNotebookPage INIT(TRUE);		/* auto-select will work regardless in some sensible cases */

/*
 * Paned widget state.
 */
GLOBAL gint			panedSliderPercent			INIT(0);	/* ## set by config, thereafter, is stale ##  */
GLOBAL gint			panedSliderFuncTreePercent	INIT(0);	/* ## set by config, thereafter, is stale ##  */
GLOBAL gint			panedSliderTextPercent		INIT(0);	/* ## set by config, thereafter, is stale ##  */

/*
 * Statusbar state.
 */
GLOBAL guint		statusbarContextId;
GLOBAL guint		statusbarMsgs INIT(0);
GLOBAL gint			statusbarRow INIT(ROW_NONE);
GLOBAL gchar*		pStatusbarInitMsg;
GLOBAL GString*		pGStringStatusbarMsg;			/* access this using Get[Record]StatusbarMsg() */
GLOBAL gint			timerStatusbar INIT(0);
GLOBAL gboolean		statusbarMsgTimeoutPending INIT(FALSE);

/*
 * Misc. widget state.
 */
GLOBAL gboolean		widgetsReady INIT(FALSE);
GLOBAL gint			widgetMainGeom[4];			/* x/y/w/h of main window */
GLOBAL gchar		mainWindowTitle[256];
GLOBAL gboolean		toolbarPlacement INIT(TOOLBAR_PLACEMENT_BELOW);
GLOBAL gboolean		kludgeWidgetGeomUseGetPosition INIT(TRUE);

/*
 * Keyboard state.
 */
GLOBAL gboolean		auxKeyPressed		INIT(FALSE);	/* if pressed, tagged line will be shown in aux. text widget */
GLOBAL int			auxKeyGdkKeyval		INIT(GDK_Shift_L);
GLOBAL int			auxKeyGdkMask		INIT(GDK_SHIFT_MASK);
GLOBAL gboolean		treeKeyPressed		INIT(FALSE);	/* if pressed, disables tree updates */
GLOBAL int			treeKeyGdkKeyval	INIT(GDK_Control_L);
GLOBAL int			treeKeyGdkMask		INIT(GDK_CONTROL_MASK);

/*
 * Editor state.
 */
GLOBAL gboolean bool_highlight_cur_line INIT(TRUE);

GLOBAL gboolean bool_space_instead_of_tabs INIT(FALSE);                                    

GLOBAL gboolean bool_show_line_numbers INIT(TRUE);

GLOBAL gboolean bool_smart_home_end INIT(TRUE);

GLOBAL gboolean bool_auto_indent INIT(TRUE);

GLOBAL gboolean bool_show_margin INIT(TRUE);

/*
 * Mouse state.
 */
GLOBAL float		mouseWheelNormal INIT(0.3);
GLOBAL float		mouseWheelFast   INIT(1.0);		/* used if Left-Ctrl is pressed */

/*
 * Find state.
 */
GLOBAL MENU_ITEM	soughtType;						/* either a tag or a text string */
GLOBAL GString*		pSoughtTag;
GLOBAL GString*		pSoughtText;
GLOBAL GString*		pSoughtModule;
GLOBAL gboolean		findCaseSensText	INIT(FALSE);	/* for string searches */
GLOBAL gboolean		findCaseSensTag		INIT(FALSE);	/* for tag    searches */
GLOBAL gboolean		findCaseSensModule	INIT(FALSE);	/* for module searches */
GLOBAL gboolean		findExactTag		INIT(FALSE);	/* for tag    searches */
GLOBAL gboolean		findExactModule		INIT(FALSE);	/* for module searches */
GLOBAL gboolean		findGlobal			INIT(FALSE);				/* for string searches */
GLOBAL gboolean		findReverse;						/* for string searches */
GLOBAL gboolean		regex				INIT(FALSE);
GLOBAL gboolean		searchMethodFoundPage;              /* results from normal or regex searching */
GLOBAL gint			searchDefault INIT(SEARCH_NORMAL);  /* default search method */
GLOBAL gint			regexScope INIT(REGEX_SCOPE_LINE);  /* scope of regex matching (one line or file) */
GLOBAL gint			findGeom[4];
GLOBAL GList**		ppGlistFindStrings;					/* ptr to pGlistFindStrings[Tag,Text,Module] */
GLOBAL GList*		pGlistFindStringsTag;
GLOBAL GList*		pGlistFindStringsText;
GLOBAL GList*		pGlistFindStringsModule;

/*
 * Goto line widget state.
 */
GLOBAL GList*		pGlistLineStrings;

/*
 * Dialog widget state.
 */
GLOBAL gboolean		buttonWordAtCursorFlag INIT(FALSE);
GLOBAL gboolean		buttonRestoreCursorFlag INIT(FALSE);
GLOBAL gboolean		dialogPlacement INIT(DIALOG_PLACEMENT_DEFAULT_WM);

/*
 * Variables assigned via the command line (or GNOME config).
 */
GLOBAL gint			tabWidth			INIT(4);		/* 4 is typical for src code files, 0 is GTK+ default */
GLOBAL gboolean		hilite				INIT(TRUE);
GLOBAL gboolean		skipFuncTree		INIT(FALSE);	/* also affects module tree -- can't be changed if tree was built!!! */
GLOBAL gboolean		skipFuncTree_pref;					/* pref code should affect this instead */
GLOBAL gboolean		vimExists			INIT(FALSE);
GLOBAL gboolean     devhelpExists       INIT(FALSE);    /* the gtk/glib/gnome devel helper*/
GLOBAL gboolean		browsingCPlusPlus	INIT(FALSE);	/* -cplusplus hidden arg */
GLOBAL gboolean		browsingJava		INIT(FALSE);    /* -java hidden arg */
GLOBAL gboolean		classQual			INIT(FALSE);

/*
 * Colors of the clist widgets.
 */
GLOBAL GdkColor colorClistWidgetTextFg
#ifdef HYPERSRC_DEFINE_GLOBALS
= { 0,
    COLOR_CLIST_WIDGET_TEXT_FG_RED,
    COLOR_CLIST_WIDGET_TEXT_FG_GREEN,
    COLOR_CLIST_WIDGET_TEXT_FG_BLUE };
#else
;
#endif

GLOBAL GdkColor colorClistWidgetTextBg
#ifdef HYPERSRC_DEFINE_GLOBALS
= { 0,
    COLOR_CLIST_WIDGET_TEXT_BG_RED,
    COLOR_CLIST_WIDGET_TEXT_BG_GREEN,
    COLOR_CLIST_WIDGET_TEXT_BG_BLUE };
#else
;
#endif

GLOBAL GdkColor colorClistWidgetSelFg
#ifdef HYPERSRC_DEFINE_GLOBALS
= { 0,
    COLOR_CLIST_WIDGET_SEL_FG_RED,
    COLOR_CLIST_WIDGET_SEL_FG_GREEN,
    COLOR_CLIST_WIDGET_SEL_FG_BLUE };
#else
;
#endif

GLOBAL GdkColor colorClistWidgetSelBg
#ifdef HYPERSRC_DEFINE_GLOBALS
= { 0,
    COLOR_CLIST_WIDGET_SEL_BG_RED,
    COLOR_CLIST_WIDGET_SEL_BG_GREEN,
    COLOR_CLIST_WIDGET_SEL_BG_BLUE };
#else
;
#endif

/*
 * Colors of the text widget.
 */
GLOBAL GdkColor colorTextWidgetTextFg
#ifdef HYPERSRC_DEFINE_GLOBALS
= { 0,
    COLOR_TEXT_WIDGET_TEXT_FG_RED,
    COLOR_TEXT_WIDGET_TEXT_FG_GREEN,
    COLOR_TEXT_WIDGET_TEXT_FG_BLUE };
#else
;
#endif

GLOBAL GdkColor colorTextWidgetTextBg
#ifdef HYPERSRC_DEFINE_GLOBALS
= { 0,
    COLOR_TEXT_WIDGET_TEXT_BG_RED,
    COLOR_TEXT_WIDGET_TEXT_BG_GREEN,
    COLOR_TEXT_WIDGET_TEXT_BG_BLUE };
#else
;
#endif

GLOBAL GdkColor colorTextWidgetSelFg
#ifdef HYPERSRC_DEFINE_GLOBALS
= { 0,
    COLOR_TEXT_WIDGET_SEL_FG_RED,
    COLOR_TEXT_WIDGET_SEL_FG_GREEN,
    COLOR_TEXT_WIDGET_SEL_FG_BLUE };
#else
;
#endif
GLOBAL GdkColor colorTextWidgetSelBg
#ifdef HYPERSRC_DEFINE_GLOBALS
= { 0,
    COLOR_TEXT_WIDGET_SEL_BG_RED,
    COLOR_TEXT_WIDGET_SEL_BG_GREEN,
    COLOR_TEXT_WIDGET_SEL_BG_BLUE };
#else
;
#endif

/*
 * Hash table for modules.
 * For speed, a hash table, not a list, is used because module names are recorded
 * (in addition to other info) while processing all the ctags lines.
 */
GLOBAL GHashTable*	pHashModules;

/*
 * Hash item of module recently loaded from a file
 * (NOT NECESSARILY THE ONE SHOWN IN TEXT WIDGET!!!)
 * Note when a module is freed, this will still point to its hash item (it won't be nullified).
 */
GLOBAL module_t*	pModuleLoaded;

/*
 * Sorted list of module names (derived from pHashModules).
 * Used to build the modules clist widget (in notebook).
 */
GLOBAL GList*		pGlistModuleNames;	/* created when tag clist is populated */

/*
 * Name of file which holds tags.
 */
GLOBAL char*		pTagsFilename;

/*
 * Maximum amount of tags that can be processed (affected by --max-tags arg).
 */
GLOBAL int			maxTags				INIT(MAX_TAGS_DEFAULT);
GLOBAL gboolean		tooManyTags			INIT(FALSE);

/*
 * Misc flags.
 */
GLOBAL int			cmdLineArgsProcessed INIT(FALSE);
GLOBAL int			showLineColumn		INIT(TRUE);
GLOBAL int			enableProcessPendingEvents INIT(TRUE);
GLOBAL int			argQuiet			INIT(FALSE);		/* true if -q was passed */
GLOBAL int			argVerbose			INIT(FALSE);		/* true if -v/-status was passed */

/*
 * Flags affecting memory/speed tradeoff.
 */
GLOBAL int			conserveMemory INIT(TRUE);		/* conserve memory at expense of speed (can change) */
GLOBAL int			speed          INIT(FALSE);		/* inverse of conserveMemory (can change) */
GLOBAL int			argSpeed       INIT(FALSE);		/* true if -speed was passed (stays true) */

/*
 * Tag sort levels.
 */
GLOBAL int			sort1;
GLOBAL int			sort2;
GLOBAL int			sort3;

/*
 * Font names.
 */
GLOBAL char			fontNameText[MAX_FONT_NAME_LEN];
GLOBAL char			fontNameList[MAX_FONT_NAME_LEN];
GLOBAL char			fontNameTree[MAX_FONT_NAME_LEN];
/*
GLOBAL char			fontNameHiliteComment[MAX_FONT_NAME_LEN];
GLOBAL char			fontNameHiliteKeyword[MAX_FONT_NAME_LEN];
GLOBAL char			fontNameHiliteType[MAX_FONT_NAME_LEN];
GLOBAL char			fontNameHiliteSymbol[MAX_FONT_NAME_LEN];
*/
/* -- copies -- */
GLOBAL char			fontNameTextCopy[MAX_FONT_NAME_LEN];
GLOBAL char			fontNameListCopy[MAX_FONT_NAME_LEN];
GLOBAL char			fontNameTreeCopy[MAX_FONT_NAME_LEN];
/*
GLOBAL char			fontNameHiliteCommentCopy[MAX_FONT_NAME_LEN];
GLOBAL char			fontNameHiliteKeywordCopy[MAX_FONT_NAME_LEN];
GLOBAL char			fontNameHiliteTypeCopy[MAX_FONT_NAME_LEN];
GLOBAL char			fontNameHiliteSymbolCopy[MAX_FONT_NAME_LEN];
*/
/* -- derived from fontNameTree -- */
GLOBAL char			fontNameTreeModule[MAX_FONT_NAME_LEN];
GLOBAL char			fontNameTreeFuncDef[MAX_FONT_NAME_LEN];
GLOBAL char			fontNameTreeFuncCall[MAX_FONT_NAME_LEN];

/*
 * Busy state of major outer-level functions.
 * Interrupting a major function to run another one
 * might confuse GTK+ and this program itself.
 * This concern is a caveat of using ProcessPendingEvents()
 * which could otherwise lead to nesting of events.
 */
GLOBAL gboolean		busy_FindStringGlobal			INIT(FALSE);
GLOBAL gboolean		busy_FindDialogClickedFind		INIT(FALSE);
GLOBAL gboolean		busy_PopulateTagsClistWidget	INIT(FALSE);
GLOBAL gboolean		busy_GotoTagUnderCursor			INIT(FALSE);
GLOBAL gboolean		busy_FindMatchesUnderCursor		INIT(FALSE);
GLOBAL gboolean		busy_SearchClistWidget_tag		INIT(FALSE);
GLOBAL gboolean		busy_SearchClistWidget_module	INIT(FALSE);
GLOBAL gboolean		busy_StepHistoryList			INIT(FALSE);
GLOBAL gboolean		busy_PropertyPageApply			INIT(FALSE);
	/* -- don't forget to update IsAnyMajorFunctionBusy() -- */

/*
 * Busy state of other functions.
 */
GLOBAL gboolean		busy_UpdateFuncTree						INIT(FALSE);
GLOBAL gboolean		busy_HyperjumpViaTreeNodeOrItem_cb		INIT(FALSE);
GLOBAL gboolean		busy_HyperjumpToModuleViaModuleTree_cb	INIT(FALSE);
GLOBAL gboolean		busy_HandlerFuncDefTreeExpand_cb		INIT(FALSE);
GLOBAL gboolean		busy_HandlerModuleTreeExpand_cb			INIT(FALSE);
	/* -- don't forget to update IsAnyTreeFunctionBusy() -- */
GLOBAL gboolean		SetSensitivityWhileBusy_cnt				INIT(0);

/*
 * Misc.
 */
GLOBAL gboolean		ctagsStdin INIT(FALSE);
GLOBAL gboolean		acceptAllTags INIT(FALSE);
GLOBAL gboolean		printStatusMsgs INIT(FALSE);	/* controls StatusMsg() */
GLOBAL gboolean		tagProcessingComplete INIT(FALSE);
GLOBAL int			maxModules INIT(MAX_MODULES_DEFAULT);
GLOBAL gboolean		knrStyle INIT(FALSE); /* K&R C style (see parser.c) */

/*
 * Multiple --langmap args.
 */
#define LANGMAP_MAX 20
GLOBAL int			langmapCnt INIT(0);
GLOBAL gchar*		langmap[LANGMAP_MAX+1];

/*
 * Vars for debugging/profiling.
 */
#ifdef HYPERSRC_DEBUG
GLOBAL GTimeVal		timeval1;
GLOBAL GTimeVal		timeval2;
#endif

#endif /* GLOBALS_H */
